<%#
 Copyright 2013-2025 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      https://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
<%_ if (clientTestFrameworkVitest) { _%>
import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest';
<%_ } _%>
import { TestBed } from '@angular/core/testing';

import { ParseLinks } from './parse-links.service';

describe('Parse links service test', () => {
  let service: ParseLinks;

  beforeEach(() => {
    service = TestBed.inject(ParseLinks);
  });

  describe('parse', () => {
    it('should throw an error when passed an empty string', () => {
      expect(function () {
        service.parse('');
      }).toThrow(new Error('input must not be of zero length'));
    });

    it('should throw an error when passed without comma', () => {
      expect(function () {
        service.parse('test');
      }).toThrow(new Error('section could not be split on ";"'));
    });

    it('should throw an error when passed without semicolon', () => {
      expect(function () {
        service.parse('test,test2');
      }).toThrow(new Error('section could not be split on ";"'));
    });

    it('should return links when headers are passed', () => {
      const links = { last: 0, first: 0 };
      expect(service.parse(' </api/audits?page=0&size=20>; rel="last",</api/audits?page=0&size=20>; rel="first"')).toEqual(links);
    });
  });
  describe('parseAll', () => {
    it('should throw an error when passed an empty string', () => {
      expect(function () {
        service.parseAll('');
      }).toThrow(new Error('input must not be of zero length'));
    });

    it('should throw an error when passed without comma', () => {
      expect(function () {
        service.parseAll('test');
      }).toThrow(new Error('section could not be split on ";"'));
    });

    it('should throw an error when passed without semicolon', () => {
      expect(function () {
        service.parseAll('test,test2');
      }).toThrow(new Error('section could not be split on ";"'));
    });

    it('should return links when headers are passed', () => {
      const links = { last: { page: '0', size: '20' }, first: { page: '0', size: '20' } };
      expect(service.parseAll(' </api/audits?page=0&size=20>; rel="last",</api/audits?page=0&size=20>; rel="first"')).toEqual(links);
    });
  });
});
